package com.empty_pro.newone;


import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    TextView txt;
    EditText et, et2;
    Button bt;
    private static final String TAG = "嗨嗨嗨";
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);//R表示资源目录

        txt = findViewById(R.id.text1);
        //txt.setText("嗨嗨嗨");
        txt.setHint("结果在此处显示");

        bt = findViewById(R.id.login);
        bt.setOnClickListener(this);

        bt.setText("计算IBM值");

        et = findViewById(R.id.et);
        //et.setText("来啦");
        et.setHint("请输入体重（单位：kg）");

        et2 = findViewById(R.id.et2);
        et2.setHint("请输入身高（单位：m）");

        Log.i(TAG, "onCreate: all done");
    }

    @Override
    public void onClick(View v) {
        Log.i(TAG, "onClick: 11111");

        String s2 = et.getText().toString();
        String s1 = et2.getText().toString();

        if (s1.length() == 0 || s2.length() == 0) {
            txt.setText("请输入完整数据");
            return;
        }
        float high = Float.parseFloat(s1);
        float weight = Float.parseFloat(s2);
        float ans = weight / (high * high);
        float res=((float)Math.round(ans*100)/100);
        String output = String.valueOf(res);
        String t1 = "您太瘦了，建议多吃点";
        String t2 = "您身体状态正好，请继续保持";
        String t3 = "您过重，建议多多锻炼";
        String t4 = "您太肥胖了，建议少吃多运动";
        String t = "";
        if (res <= 18.4) t = t1;
        else if (res <= 23.9) t = t2;
        else if (res <= 27.9) t = t3;
        else t = t4;
        txt.setText("您的IBM值为 " + res + " "+ t);
        Log.i(TAG, "onClick: done");
    }

}